package app.cn.com.school.activity

import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.View
import app.cn.com.school.R
import app.cn.com.school.adapter.MyViewPagerAdapter
import app.cn.com.school.databinding.ActivitySearchBinding
import app.cn.com.school.fragment.SearchItemFragment
import app.cn.com.school.tools.Constants


class SearchActivity : BaseActivity<ActivitySearchBinding>() {
    override fun initBindingVar() {
    }

    override fun initTitle() {
        binding.titlebar.back.setOnClickListener { finish() }

    }

    private var fragemnts = ArrayList<Fragment>()
    private var titles = arrayOf("商品", "店铺")
    lateinit var context: Context
    private var adapter: MyViewPagerAdapter? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initBinding(R.layout.activity_search)
        context = this
        initView()
    }


    private fun initView() {

        var type = this.intent.getStringExtra("type").toInt()
        when (type) {
            0 -> {
                binding.imgBack.setOnClickListener { finish() }
                /// 首页搜索数据

            }
            1 -> {
                binding.imgBack.setOnClickListener {
                    binding.titlebar.linTitleBar.visibility = View.VISIBLE
                    binding.linSe.visibility = View.GONE
                }
                titles = arrayOf("店铺", "商品")
                binding.linSe.visibility = View.GONE
                binding.titlebar.linTitleBar.visibility = View.VISIBLE
                binding.titlebar.menuDate.visibility = View.VISIBLE
                binding.titlebar.menuDate.setImageResource(R.mipmap.seek)
                binding.titlebar.menuDate.setOnClickListener {
                    binding.titlebar.linTitleBar.visibility = View.GONE
                    binding.linSe.visibility = View.VISIBLE
                }
                binding.titlebar.title.text = "没事---"

            }
        }

        binding.btnSearch.setOnClickListener {
            binding.linOld.visibility = View.GONE  //搜素历史
        }
        fragemnts.add(SearchItemFragment().newInstance(1))
        fragemnts.add(SearchItemFragment().newInstance(2))
        adapter = MyViewPagerAdapter(supportFragmentManager, fragemnts, titles)
        binding.searchViewpager.adapter = adapter
        binding.searchTab.setupWithViewPager(binding.searchViewpager)
        binding.searchTab.setTabsFromPagerAdapter(adapter)
        binding.searchTab.post { Constants.setIndicator(binding.searchTab, 50, 50) }
    }


}
